#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author : bird.zhang@ximalaya.com

import pika

# 建立一个实例
connection = pika.BlockingConnection(
    # 默认端口5672，可不写
    pika.ConnectionParameters(host='192.168.3.161', port=5672, virtual_host='/',
                              credentials=pika.PlainCredentials('guest', 'guest'))
)
# 声明一个管道，在管道里发消息
channel = connection.channel()

# 在管道里声明queue
# RabbitMQ a message can never be sent directly to the queue, it always needs to go through an exchange.
# channel.queue_declare(queue='test.lamia.admin.live.room.queue')

# 消息内容
msg1 = {
    'ttl': 30
}

channel.basic_publish(exchange='ex.test.ttl', routing_key='', body=str(msg1),
                      properties=pika.BasicProperties(expiration=str(msg1['ttl'] * 1000)))

msg2 = {
    'ttl': 10
}

channel.basic_publish(exchange='ex.test.ttl', routing_key='', body=str(msg2),
                      properties=pika.BasicProperties(expiration=str(msg2['ttl'] * 1000)))

# 队列关闭
connection.close()
